package sqy.bookstore.admin.web.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.itcast.servlet.BaseServlet;
import sqy.bookstore.admin.service.AdminselectImpl;
import sqy.bookstore.book.domain.Book;

@WebServlet("/selectServlet")
public class SelectServlet extends BaseServlet{
	
	public String select(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//Map<String, String[]> condition = request.getParameterMap();
		String cname = request.getParameter("cname");
		String bname = request.getParameter("bname");
		System.out.println(cname);
		System.out.println(bname);
		AdminselectImpl service = new AdminselectImpl();
	    List<Book> bookList = service.findSelect(cname,bname);
	    if(bookList==null){
	    	System.out.println(5);
	    	return "r:/adminjsps/admin/index.jsp";
	    	//response.sendRedirect(request.getContextPath()+"/adminjsps/admin/index.jsp");
	    }else {
			System.out.println(1);
		request.setAttribute("bookList", bookList);
		//return "f:/adminjsps/admin/book/list.jsp";
			//request.getSession().setAttribute("bookList", bookList);
			//response.sendRedirect(request.getContextPath()+"/adminjsps/list.jsp");
		return "f:/adminjsps/list.jsp";
		}
		
		
		
	
	}
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}

}
